CREATE PROCEDURE coreWFTasksGetOperatorTasks
(
	@OperatorID		int,
	@GroupList		nvarchar(500)
)
AS

IF @GroupList = ''
BEGIN
	SELECT * FROM WFTasks WHERE 
	
			StartDT<GETDATE() 
		AND FK_ForOperatorID = @OperatorID
	
	ORDER BY DueDT;
END
ELSE
BEGIN

	DECLARE @sql varchar(5000);
	SET @sql = 'SELECT * FROM WFTasks WHERE StartDT<GETDATE() AND ((FK_ForOperatorID = ';
	SET @sql = @sql + CAST(@OperatorID as nvarchar(50)) + ') OR (FK_ForOperatorGroupID in (';
	SET @sql = @sql + @GroupList + '))) ORDER BY DueDT;';
	exec(@sql);

END
